﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MyWeb.ServiceBus.Model
{
    /// <summary>
    /// 通用分页信息类
    /// </summary>
    public class PageModel
    {
        /// <summary>
        /// 当前页标
        /// </summary>
        public int Page { get; set; } = 1;
        /// <summary>
        /// 总页数
        /// </summary>
        public int PageCount => (int)Math.Ceiling((decimal)DataCount / PageSize);
        /// <summary>
        /// 数据总数
        /// </summary>
        public int DataCount { get; set; } = 0;
        /// <summary>
        /// 每页大小
        /// </summary>
        public int PageSize { set; get; } = 20;
        /// <summary>
        /// 返回数据
        /// </summary>
        public object? Data { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public PageModel() { }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="page"></param>
        /// <param name="dataCount"></param>
        /// <param name="pageSize"></param>
        /// <param name="data"></param>
        public PageModel(int page, int dataCount, int pageSize, object? data = null)
        {
            this.Page = page;
            this.DataCount = dataCount;
            this.PageSize = pageSize;
            this.Data = data;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <typeparam name="TOut"></typeparam>
        /// <returns></returns>
        public PageModel ConvertTo<TOut>()
        {
            return new PageModel(Page, DataCount, PageSize, default);
        }
    }
}
